<?php
namespace Home\Service;

use Think\Service\BasicService;

class UserService extends BasicService {
    public function insert($model) {
        return $this->db->add($model);
    }

    public function remove($condition) {
        return $this->db->where($condition)->delete();
    }

    public function update($where, $model = array()) {
        return $this->db->where($where)->save($model);
    }

    public function find($condition) {
        return $this->db->find($condition);
    }

    public function query($condition) {
        $data = $this->db->where($condition)->order('created desc')->select();
        foreach ($data as $k => $v) {
            $this->db = M('yz_order_info');
            $datas = $this->db->where(array('oid' => $v['tid']))->select();
            $data[$k]['goodsdata'] = $datas;
            switch ($v['status']) {
                case 'TRADE_NO_CREATE_PAY':
                    $data[$k]['status'] = '没有创建支付交易';
                    break;
                case 'WAIT_BUYER_PAY':
                    $data[$k]['status'] = '等待买家付款';
                    break;
                case 'WAIT_GROUP':
                    $data[$k]['status'] = '等待成团';
                    break;
                case 'WAIT_SELLER_SEND_GOODS':
                    $data[$k]['status'] = '等待卖家发货';
                    break;
                case 'WAIT_BUYER_CONFIRM_GOODS':
                    $data[$k]['status'] = '等待买家确认收货';
                    break;
                case 'TRADE_BUYER_SIGNED':
                    $data[$k]['status'] = '买家已签收';
                    break;
                case 'TRADE_CLOSED':
                    $data[$k]['status'] = '付款以后用户退款成功，交易自动关闭';
                    break;
                case 'ALL_WAIT_PAY':
                    $data[$k]['status'] = '包含：WAIT_BUYER_PAY、TRADE_NO_CREATE_PAY';
                    break;
                case 'ALL_CLOSED':
                    $data[$k]['status'] = '所有关闭订单';
                    break;
                default:
                    $data[$k]['status'] = '其他';
            }
        }
        return $data;
    }


}

?>